#!/bin/sh -e

for patch in *.patch; do
    patch -p1 < "$patch"
done

./configure \
    --prefix=/usr \
    --enable-shared \
    --enable-static \
    --with-system-expat \
    --with-system-ffi \
    --with-ssl-default-suites='TLSv1.3:TLSv1.2+AEAD+ECDHE:TLSv1.2+AEAD+DHE' \
    --with-ensurepip=yes

make
make DESTDIR="$1" install

ln -s python3 "$1/usr/bin/python"
ln -s pip3    "$1/usr/bin/pip"

# Make static library writable.
chmod -v u+w "$1/usr/lib/libpython"*
